package de.baumann.browser.activitys.center

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import de.baumann.browser.OdinGlideModule
import de.baumann.browser.R
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.iview.IRequestLicenceView
import de.baumann.browser.present.RequestLicencePresenter
import de.baumann.browser.views.dialog.Callback
import de.baumann.browser.views.dialog.VaptchaDialog
import kotlinx.android.synthetic.main.activity_request_licence.*
import kotlinx.android.synthetic.main.include_tool_bar.*

/**
 *@author:
 *@date:2019/7/2 14:22
 *@discription: 索要Licence
 */
class RequestLicenceActivity : BaseOdinActivity<IRequestLicenceView, RequestLicencePresenter>(), IRequestLicenceView {

    private var invitePhone = ""
    private var poolPhone = ""

    companion object {
        fun startRequestLicenceActivity(context: Context,licenceCount:Int) {
           val intent =  Intent(context, RequestLicenceActivity::class.java).apply {
                putExtra("licenceCount",licenceCount)
            }
            context.startActivity(intent)
        }
    }

    override fun getLayout(): Int {
        return R.layout.activity_request_licence
    }

    @SuppressLint("SetTextI18n")
    override fun initView() {
        initToolbar(commToolBar,commTitle)
        tvLicenceCount.text = "${intent.getIntExtra("licenceCount",0)} Licence"
        btnRequestLicence.setOnClickListener {
            VaptchaDialog(mContext,object :Callback{
                override fun callback(token: String) {
                    runOnUiThread {
                        presenter.requestLicence(invitePhone, poolPhone,token)
                    }
                }
            }).show()
        }
    }

    override fun createPresenter(): RequestLicencePresenter {
       return RequestLicencePresenter()
    }

    override fun createView(): IRequestLicenceView {
        return this
    }

    override fun initData() {
        presenter.inviteAndPoolInfo()

    }

    override fun getTitleText(): String {
        return getString(R.string.ask_for_licence)
    }

    override fun setInvitePhone(invPhone: String?) {
        if (invPhone != null) {
            invitePhone = invPhone
            tvInvitePhone.text = invPhone
        }
    }

    override fun setInviteAvatar(invAvatar: String?) {
        if (invAvatar == null) {
            return
        }
        OdinGlideModule.loadWithCropAndCircle(mContext, invAvatar, ivInviteAvatar, R.drawable.icon_head)
    }

    override fun setPoolPhone(poolPhone: String?) {
        if (poolPhone != null) {
            this.poolPhone = poolPhone
            tvPoolPhone.text = poolPhone
        }
    }

    override fun setPoolAvatar(poolAvatar: String?) {
        if (poolAvatar == null) {
            return
        }
        OdinGlideModule.loadWithCropAndCircle(mContext, poolAvatar, ivPoolAvatar, R.drawable.icon_head)
    }

    override fun requestSuccess() {
        showShortToast(getString(R.string.please_wait_patiently))
        finish()
    }

    override fun setInviteTip(invTip: String) {
        tvInviteDesc.text = invTip
    }

    override fun setPoolTip(poolTip: String) {
        tvPoolDesc.text = poolTip
    }

}
